package dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.support.v7.widget.AppCompatCheckBox;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import beans.UserRightsBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import constants.Constants;
import custom.MyDialog;

/**
 * Created by Administrator on 2018/5/12.
 */

public class UserRightsDialog extends MyDialog {
    @BindView(R.id.tv_dialog_user_rights_number)
    TextView tvNumber;
    @BindView(R.id.tv_dialog_user_rights_name)
    TextView tvName;
    @BindView(R.id.cb_dialog_user_rights_manage)
    AppCompatCheckBox cbManage;
    @BindView(R.id.cb_dialog_user_rights_head_nurse)
    AppCompatCheckBox cbHeadNurse;
    @BindView(R.id.cb_dialog_user_rights_nurse)
    AppCompatCheckBox cbNurse;
    //    @BindView(R.id.cb_dialog_user_rights_enable)
//    AppCompatCheckBox cbEnable;
//    @BindView(R.id.cb_dialog_user_rights_disable)
//    AppCompatCheckBox cbDisable;
    @BindView(R.id.tv_dialog_user_rights_cancle)
    TextView tvCancle;
    @BindView(R.id.tv_dialog_user_rights_sure)
    TextView tvSure;

    private UserRightsBean userRightsBean;
    //    private String enable;
    private int roleInfoId;
    private OnClickListener onClickListener;

    public UserRightsDialog(@NonNull Context context, @StyleRes int themeResId, UserRightsBean userRightsBean, OnClickListener onClickListener) {
        super(context, themeResId);
        this.userRightsBean = userRightsBean;
        this.onClickListener = onClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_user_rights);
        ButterKnife.bind(this);
        tvNumber.setText(userRightsBean.getNumber());
        tvName.setText(userRightsBean.getName());
        if (userRightsBean.getRoleInfoId() == Constants.ROLE_NURSE) {
            cbNurse.setChecked(true);
        } else if (userRightsBean.getRoleInfoId() == Constants.ROLE_HEAD_NURSE) {
            cbHeadNurse.setChecked(true);
        } else if (userRightsBean.getRoleInfoId() == Constants.ROLE_MANAGE) {
            cbManage.setChecked(true);
        }
        roleInfoId = userRightsBean.getRoleInfoId();
//        if (userRightsBean.isEnable()) {
//            cbEnable.setChecked(true);
//            enable = "True";
//        } else {
//            cbDisable.setChecked(true);
//            enable = "False";
//        }
    }

    @OnClick({R.id.cb_dialog_user_rights_manage, R.id.cb_dialog_user_rights_head_nurse, R.id.cb_dialog_user_rights_nurse, R.id.tv_dialog_user_rights_cancle, R.id.tv_dialog_user_rights_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cb_dialog_user_rights_manage:
                cbHeadNurse.setChecked(false);
                cbNurse.setChecked(false);
                roleInfoId = Constants.ROLE_MANAGE;
                break;
            case R.id.cb_dialog_user_rights_head_nurse:
                cbManage.setChecked(false);
                cbNurse.setChecked(false);
                roleInfoId = Constants.ROLE_HEAD_NURSE;
                break;
            case R.id.cb_dialog_user_rights_nurse:
                cbHeadNurse.setChecked(false);
                cbManage.setChecked(false);
                roleInfoId = Constants.ROLE_NURSE;
                break;
//            case R.id.cb_dialog_user_rights_enable:
//                enable = "True";
//                cbDisable.setChecked(false);
//                break;
//            case R.id.cb_dialog_user_rights_disable:
//                cbEnable.setChecked(false);
//                enable = "False";
//                break;
            case R.id.tv_dialog_user_rights_cancle:
                dismiss();
                break;
            case R.id.tv_dialog_user_rights_sure:
                onClickListener.onChangeClickListener(roleInfoId, userRightsBean.getName(), this);
                break;
        }
    }

    public interface OnClickListener {
        void onChangeClickListener(int roleInfoId, String name, UserRightsDialog dialog);
    }
}
